<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 * @param $code
 * @param bool $mini
 * @return array|mixed
 */
function error_code($code, $mini = false)
{
    $result = [
        'status' => false,
        'data' => 10000,
        'msg' => config('error.10000')
    ];
    if (config('?error.' . $code)) {
        $result['data'] = $code;
        $result['msg'] = config('error.' . $code);
    }
    if ($mini) {
        return $result['msg'];
    } else {
        return $result;
    }
}
/**
 * 通用化API接口数据输出 成功
 * @param array $data 返回数据
 * @param string $msg 消息
 * @param int $httpCode 状态码
 * @return \think\response\Json
 */
function showOk($data = [], $msg = 'ok')
{
    return  array_merge( $data,['code' => true, 'msg' => $msg]);
}

/**
 *  通用化API接口数据输出 错误
 * @param string $msg 消息
 * @param string $code 业务码
 * @param int $httpCode 状态码
 * @return \think\response\Json
 */
function showErr($msg = '错误', $code = '')
{
    return ['code' => false, 'msg' => $msg, 'data' => $code];
}